package com.springBoot.config;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import com.alibaba.druid.pool.DruidDataSource;
/**
 * 
 * @说明配置数据源<br/>
 * @注与springBoot1.5版本不同之处,这里要手动添加<br/>
 * @作者徐晓辉<br/>
 * @日期2018年11月8日<br/>
 */
@Configuration
public class DataSourceConfig {
 
	@Autowired
	private Environment env;
 
	@Bean(name = "myDataSource")
    @Qualifier("myDataSource")
	public DataSource getDataSource() {
		DruidDataSource dataSource = new DruidDataSource();
		dataSource.setUrl(env.getProperty("spring.datasource.url"));
		dataSource.setUsername(env.getProperty("spring.datasource.username"));
		dataSource.setPassword(env.getProperty("spring.datasource.password"));
		return dataSource;
	}
}

